package com.xcity.util;

import java.util.AbstractList;

/**
 * 不可修改的List，且getArray时直接返回原数组，不用copy一个副本
 * @author yang.li
 *
 * @param <E>
 */
public class ArrayList<E> extends AbstractList<E> {
	
	private E[] ref;
	
	public ArrayList(E[] ref) {
		this.ref = ref;
	}

	@Override
	public E get(int index) {
		return ref[index];
	}

	@Override
	public int size() {
		return ref.length;
	}

	@Override
	public Object[] toArray() {
		// DON'T NEW COPY
		return ref;
	}

	@Override
	public <T> T[] toArray(T[] a) {
		// DON'T NEW COPY
		return (T[]) ref;
	}

}
